package com.ymttest.business.service;

import com.ymatou.iapi.productimporter.parameter.CreateBean;
import com.ymatou.iapi.productimporter.parameter.CreateTaskPacketDto;
import com.ymatou.iapi.productimporter.parameter.ExecuteBean;
import com.ymatou.iapi.productimporter.service.CreateCall;
import com.ymatou.iapi.productimporter.service.ExecuteCall;
import com.ymttest.utils.TestDataManager;

import java.io.IOException;
import java.util.Arrays;

public class ProductImporterCallService {

    public static CreateBean initCreateBean(int sellerId){
        CreateBean createBean = new CreateBean();
        createBean.setAppId("AutoTest");
        createBean.setSellerId(sellerId);
        createBean.setFileName("测试"+ TestDataManager.getRandomNum(5)+".zip");
        createBean.setFileSign("import"+TestDataManager.getRandomNum(6));
        CreateTaskPacketDto createTaskPacketDto = new CreateTaskPacketDto();
        createTaskPacketDto.setPacketNo(Integer.parseInt(TestDataManager.getRandomNum(6)));
        createTaskPacketDto.setPacketUrl("http://111");
        createBean.setPacketList(Arrays.asList(createTaskPacketDto));
        return createBean;
    }

    public static int create(CreateBean createBean) throws IOException {
        CreateCall createCall = new CreateCall();
        createCall.setData(createBean);
        createCall.callService();
        int taskId = createCall.getJsonObject().get("data").getAsJsonObject().get("taskId").getAsInt();
        return taskId;
    }

    public static void execute(int taskId,String appId) throws IOException {
        ExecuteBean executeBean = new ExecuteBean();
        executeBean.setTaskId(taskId);
        executeBean.setAppId(appId);
        ExecuteCall executeCall = new ExecuteCall();
        executeCall.setData(executeBean);
        executeCall.callService();
    }
}
